package Meta

import (
	"context"
	"database/sql"
	"db2s/global"
	"db2s/outPut"
	"db2s/parDef"
	"time"
)

type (
	Object struct {
		Schema  string
		Table   string
		MSchema string
		MTable  string
	}
	Options struct {
		Scn             string
		SqlExecStopTime time.Duration
		//Esa                 EncryptionProperties
		WhereSql            string
		WhereAdd            string
		SqlMode             bool
		TablePx             string
		FixRows             int64
		LowerCaseTableNames bool
		SqlLogBin           bool //是否忽略binlog
		//Partition           PartitionOptions
		RepairMethod string //应用sql修复方式
	}
	ExecDDL struct {
		Sql       string                `json:"sqlText"`
		FilePoint outPut.FileOperations `json:"-"`
	}
	Parameter struct {
		Con                 []*sql.DB
		Meta                []any
		Object              Object `json:"object"`
		IndexColumnBaseData any
		Options             Options `json:"options"`
		ExecDDL             ExecDDL `json:"execDDL"`
	}
	Meta struct {
		Drive      []string
		Role       string
		Join       string
		Parameter  Parameter `json:"parameter"`
		Parameter1 []parDef.Parameter
	}
)
type BaseEr interface {
	Set(parameter string, value any) (err error)
	Result(object string) global.Return
}
type TableEr interface {
	Schema(ctx context.Context) (result global.Return, err error)
	Existence(ctx context.Context) (result global.Return, err error)
	Name(ctx context.Context) (result global.Return, err error)
	Comment(ctx context.Context) (result global.Return, err error)
	Character(ctx context.Context) (result global.Return, err error)
	Collation(ctx context.Context) (result global.Return, err error)
	Constraints(ctx context.Context) (result global.Return, err error)
	Drop(ctx context.Context) (result global.Return, err error)
	Recover(ctx context.Context) (result global.Return, err error)
	Rename(ctx context.Context) (result global.Return, err error)
	Truncate(ctx context.Context) (result global.Return, err error)
	PartNameToShardName(ctx context.Context) (result global.Return, err error)
	Analyze(ctx context.Context) (result global.Return, err error)
	ExecDDL(ctx context.Context) (result global.Return, err error)
	CreateGeneral(ctx context.Context) (result global.Return, err error)
	CreatePrint(ctx context.Context) (result global.Return, err error)
	AlterGeneral(ctx context.Context) (result global.Return, err error)
}
type ColumnEr interface {
	Comment(ctx context.Context) (result global.Return, err error)
	LobMeta(ctx context.Context) (result global.Return, err error)
	BigVarcharMeta(ctx context.Context) (result global.Return, err error)
	Meta(ctx context.Context) (result global.Return, err error)
	MetaMap(ctx context.Context) (result global.Return, err error)
	ColumnAttributeMapClip(ctx context.Context) (result global.Return, err error)
}
type IndexEr interface {
	NameColumn(ctx context.Context) (result global.Return, err error)
	KeyChoose(ctx context.Context) (result global.Return, err error)
	NameToColumnClip(ctx context.Context) (result global.Return, err error)
}
type PartitionEr interface {
	PartType(ctx context.Context) (result global.Return, err error)
	PartSum(ctx context.Context) (result global.Return, err error)
	PartMeta(ctx context.Context) (result global.Return, err error)
	NameToRuleClip(ctx context.Context) (result global.Return, err error)
}
type ViewEr interface {
	Existence(Con *sql.DB) (result global.Return, err error)
	Name(Con *sql.DB) (result global.Return, err error)
	ViewDrop(Con *sql.DB) (result global.Return, err error)
	ViewDefinition(Con *sql.DB) (result global.Return, err error)
}
type SeqEr interface {
	SeqName(ctx context.Context) (result global.Return, err error)
	SeqExistence(ctx context.Context) (result global.Return, err error)
	SeqDrop(ctx context.Context) (result global.Return, err error)
	SeqDefinition(ctx context.Context) (result global.Return, err error)
	SeqCreate(ctx context.Context) (result global.Return, err error)
	SeqPrint(ctx context.Context) (result global.Return, err error)
}
type JobEr interface {
	BaseEr
	Existence(Con *sql.DB) (result global.Return, err error)
	Name(Con *sql.DB) (result global.Return, err error)
	JobDefinition(Con *sql.DB) (result global.Return, err error)
}
type TriggerEr interface {
	BaseEr
	Existence(Con *sql.DB) (result global.Return, err error)
	Name(Con *sql.DB) (result global.Return, err error)
	TriggerDefinition(Con *sql.DB) (result global.Return, err error)
}
type ForeignEr interface {
	BaseEr
	Existence(Con *sql.DB) (result global.Return, err error)
	Name(Con *sql.DB) (result global.Return, err error)
	ForeignDefinition(Con *sql.DB) (result global.Return, err error)
}
type ProcedureEr interface {
	BaseEr
	Existence(Con *sql.DB) (result global.Return, err error)
	Name(Con *sql.DB) (result global.Return, err error)
	ProcedureDefinition(Con *sql.DB) (result global.Return, err error)
}
type FuncEr interface {
	BaseEr
	Existence(Con *sql.DB) (result global.Return, err error)
	Name(Con *sql.DB) (result global.Return, err error)
	FuncDefinition(Con *sql.DB) (result global.Return, err error)
}
type TypeEr interface {
	BaseEr
	Existence(Con *sql.DB) (result global.Return, err error)
	Name(Con *sql.DB) (result global.Return, err error)
	TypeDefinition(Con *sql.DB) (result global.Return, err error)
}
type PackageEr interface {
	BaseEr
	Existence(Con *sql.DB) (result global.Return, err error)
	Name(Con *sql.DB) (result global.Return, err error)
	PackageDefinition(Con *sql.DB) (result global.Return, err error)
}
type ObjectEr interface {
	IndexEr
	PartitionEr
	ViewEr
	SeqEr
	JobEr
	TriggerEr
	ForeignEr
	ProcedureEr
	FuncEr
	TypeEr
}
